package com.hzw.service.impl;

import com.hzw.bean.ArticleCategory;
import com.hzw.dao.ArticleCategoryMapper;
import com.hzw.service.ArticleCategoryService;
import com.hzw.utils.UUIDUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/3/28.
 */
@Service
public class ArticleCategoryServiceImpl implements ArticleCategoryService {
    @Resource
    private ArticleCategoryMapper articleCategoryMapper;

    /**
     * 新增分类
     * @param articleCategory
     */
    @Override
    public void addArticleCategory(ArticleCategory articleCategory) {
        String id = UUIDUtils.getUUID();
        articleCategory.setId(id);
        articleCategoryMapper.insertSelective(articleCategory);
    }

    /**
     * 通过Id删除文章分类(软删除)
     * @param categoryId
     * @return
     */
    @Override
    public int deleteArticleCategoryById(String categoryId) {
        return articleCategoryMapper.deleteArticleCategoryById(categoryId);
    }

    /**
     * 更新文章分类:只更新非空字段
     * @param articleCategory
     * @return
     */
    @Override
    public int updateArticleCategoryById(ArticleCategory articleCategory) {
        return articleCategoryMapper.updateByPrimaryKeySelective(articleCategory);
    }


    /**
     * 根据Id查找文章分类
     * @param categoryId
     * @return
     */
    @Override
    public ArticleCategory selectArticleCategoryById(String categoryId) {
        return articleCategoryMapper.selectArticleCategoryById(categoryId);
    }

    /**
     * 查找所有的文章分类
     * @return
     */
    @Override
    public List<ArticleCategory> selectAllArticleCategory() {
        return articleCategoryMapper.selectAllArticleCategory();
    }

    /**
     * 判断type是否已存在
     * @param type
     * @return
     */
    @Override
    public int checkExistType(int type) {
        return articleCategoryMapper.checkExistType(type);
    }
}
